import { verifyAccessToken } from '~/utils/jwt-utils';
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
import { queryDatabase } from '~/functions';

export default eventHandler(async (event) => {
  const userinfo = verifyAccessToken(event);
  if (!userinfo) {
    return unAuthorizedResponse(event);
  }
  // 从数据库查询
  let queryString = `SELECT DISTINCT name FROM bmi ORDER BY name ASC`;
  const results = <any[]>await queryDatabase(queryString, []);

  if (results.length > 0) {
    return useResponseSuccess(results);
  } else {
    return useResponseSuccess([]);
  }
});
